﻿namespace AnyOffice.WebControls
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    internal class DataListBigIcoTemplate : ITemplate
    {
        private string _imageUrl;
        private string strUrl;
        private string strUrlName;

        public DataListBigIcoTemplate(string imageUrl, string Url, string UrlName)
        {
            this._imageUrl = imageUrl;
            this.strUrl = Url;
            this.strUrlName = UrlName;
        }

        public void InstantiateIn(Control container)
        {
            WebControl child = new WebControl(HtmlTextWriterTag.A);
            child.DataBinding += new EventHandler(this.OnADataBinding);
            Image image = new Image();
            image.ID = "Ico";
            image.ImageUrl = this._imageUrl;
            image.DataBinding += new EventHandler(this.OnImageDataBinding);
            child.Controls.Add(image);
            child.Controls.Add(new WebControl(HtmlTextWriterTag.Br));
            Label label = new Label();
            label.ID = "Title";
            label.DataBinding += new EventHandler(this.OnDataBinding);
            child.Controls.Add(label);
            container.Controls.Add(child);
        }

        public void OnADataBinding(object sender, EventArgs e)
        {
            string str = DataBinder.Eval(((WebControl) sender).NamingContainer, "DataItem." + this.strUrl).ToString();
            ((WebControl) sender).Attributes.Add("href", str);
        }

        public void OnDataBinding(object sender, EventArgs e)
        {
            ((Label) sender).Text = DataBinder.Eval(((Label) sender).NamingContainer, "DataItem." + this.strUrlName).ToString();
        }

        public void OnImageDataBinding(object sender, EventArgs e)
        {
            ((Image) sender).ImageUrl = this._imageUrl;
        }
    }
}

